/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode* cur=head;
        stack<int> ptr;
        while(cur){
            ptr.push(cur->val);
            cur=cur->next;
        }
        cur=head;
        while(cur){
            cur->val=ptr.top();
            ptr.pop();
            cur=cur->next;
        }
        return head;
    }
};